<?php 
	session_start();
    require_once("dbcon.php");
	
	if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true):
	
		$getRooms = "SELECT *
        			 FROM chat_rooms";
        $roomResults = mysql_query($getRooms);	  
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<header>
	<link rel="stylesheet" type="text/css" href="main.css"/>
				<div id="titre_principal">

					<img src="images/logo.png"  id="logo" />

				</div>

				<nav>
						<?php
						if (isset($_SESSION['signed_in']) && $_SESSION['signed_in']) {
							echo 'Hello <b>' . htmlentities($_SESSION['user_email']) . '</b>. Not you? <a class="item" href="logout.php">Sign out</a>';
						} else {
							echo '<a class="item" href="login.php">Sign in</a> or <a class="item" href="inscription.php">create an account</a>.';
						}
						?>

					
							<a href="index.php">Accueil</a>
					

						<?php
						if (isset($_SESSION['signed_in']) && $_SESSION['signed_in']) {
						?>
						
							<a href="public_profile.php">My profile</a>
						

					
							<a href="forum/index.php">Forum</a>
					
					
							<a href="chat/chatrooms.php">Chat</a>
					
						<?php
						} else {
						?>
						<?php
						}
						?>
				</nav>
			</header>
<body>

    <div id="page-wrap"> 
    
    	<div id="header">
        	
        </div>
        
    	<div id="section">
    	
            <div id="rooms">
            	<h3>Rooms</h3>
                <ul>
                    <?php 
                        while($rooms = mysql_fetch_array($roomResults)):
                            $room = $rooms['name'];
                            $query = mysql_query("SELECT * FROM `chat_users_rooms` WHERE `room` = '$room' ") or die("Cannot find data". mysql_error());
                            $numOfUsers = mysql_num_rows($query);
                    ?>
                    <li>
                        <a href="room/?name=<?php echo $rooms['name']?>"><?php echo $rooms['name'] . "<span>Users chatting: <strong>" . $numOfUsers . "</strong></span>" ?></a>
                    </li>
                    <?php endwhile; ?>
                </ul>
            </div>
        </div>
        
    </div>

</body>

</html>

<?php
else:
echo '<a class="item" href="../login.php">Sign in</a> or <a class="item" href="../inscription.php">create an account to access the Chat.</a>';
endif;
?>
